﻿@{ 
    Layout = null; TBM.Models.User UserInfo = (TBM.Models.User)ViewBag.UserInfo;
    List<TBM.Models.MainMenu> MenuList = (List<TBM.Models.MainMenu>)ViewBag.MainMenu;
    string LargePic = TBM.Core.Config.DefaultPic;
    string SmallPic = LargePic;
    if(!String.IsNullOrEmpty(UserInfo.PicUrl)){
        LargePic = UserInfo.PicUrl + "large.png?" + DateTime.Now.Ticks;
        SmallPic = UserInfo.PicUrl + "small.png?" + DateTime.Now.Ticks;
    }
}
@helper TreeNodes(TBM.Models.MainMenu parent){
	if(parent.SubMenu != null && parent.SubMenu.Any()){
		foreach(TBM.Models.MainMenu item in parent.SubMenu){
			<div class="pl-50 mt-5">
				<label class="checkbox-inline align-left">
					@if(item.IsChecked){
						<input type="checkbox" name="id" value="@item.ID" checked="checked" @(ViewBag.IsCurrentUser ? "disabled=\"disabled\"" : "")> 
					}else{
						<input type="checkbox" name="id" value="@item.ID"> 
					}
					@item.PageName
				</label>
				@TreeNodes(item)
			</div>
		}
	}
}
<div class="profile-container">
  <div class="row">
    <div class="col-md-12">
      <!-- BEGIN PROFILE SIDEBAR -->
      <div class="profile-sidebar" style="width:250px;">
        <!-- PORTLET MAIN -->
        <div class="portlet light profile-sidebar-portlet">
          <!-- SIDEBAR USERPIC -->
          <div id="profile_userpic" class="profile-userpic">
            <img src="@LargePic" class="img-responsive" />
          </div>
          <!-- END SIDEBAR USERPIC -->
          <!-- SIDEBAR USER TITLE -->
          <div class="profile-usertitle">
            <div id="profile_primary_fullname" class="profile-usertitle-name">
              @if(UserInfo.CNName){
                @(UserInfo.FirstName + UserInfo.LastName)
              }else{
                @(UserInfo.LastName + " " + UserInfo.FirstName)
              }
            </div>
            <div class="profile-usertitle-uid">
              ( UID: @UserInfo.UID )
            </div>
            <div class="profile-usertitle-job">
              @UserInfo.Groups
            </div>
          </div>
          <!-- END SIDEBAR USER TITLE -->
          <!-- SIDEBAR MENU -->
          <div class="profile-usermenu">
            <ul class="nav">
              <li class="active">
                <a href="javascript:;">
                  <i class="icon-settings"></i>
                  账户配置
                </a>
              </li>
            </ul>
          </div>
          <!-- END MENU -->
        </div>
        <!-- END PORTLET MAIN -->
        <!-- PORTLET MAIN -->
        <div class="portlet light">
          <!-- STAT -->
          <div class="row">
          </div>
          <!-- END STAT -->
          <div>
            <h4 id="profile_fullname" class="profile-desc-title">
              关于 @if(UserInfo.CNName){
              @(UserInfo.FirstName + UserInfo.LastName)
              }else{
              @(UserInfo.LastName + " " + UserInfo.FirstName)
              }
            </h4>
            <span id="profile_memo" class="profile-desc-text"> @(String.IsNullOrEmpty(UserInfo.Memo) ? "什么信息都没有留下" : UserInfo.Memo) </span>
            <div class="margin-top-20 profile-desc-link">
              <i class="fa fa-envelope-o"></i>
              <a id="profile_email" href="mailto:@UserInfo.Email">@UserInfo.Email</a>
            </div>
            <div class="margin-top-20 profile-desc-link">
              <i class="fa fa-phone"></i>
              <span id="profile_phone">@UserInfo.Phone</span>
            </div>
            <div class="margin-top-20 profile-desc-link">
              <i class="fa fa-qq"></i>
              <span id="profile_qq">@UserInfo.QQ</span>
            </div>
          </div>
        </div>
        <!-- END PORTLET MAIN -->
      </div>
      <!-- END BEGIN PROFILE SIDEBAR -->
      <!-- BEGIN PROFILE CONTENT -->
      <div class="profile-content">
        <div class="row">
          <div class="col-md-12">
            <div class="portlet light">
              <div class="portlet-title tabbable-line">
                <div class="caption caption-md">
                  <span class="caption-subject font-blue-madison bold uppercase">账户信息</span>
                </div>
                <ul class="nav nav-tabs">
                  <li class="active">
                    <a href="#tab_profile" data-toggle="tab">个人信息</a>
                  </li>
                  <li>
                    <a href="#tab_avatar" data-toggle="tab">更改头像</a>
                  </li>
                  <li>
                    <a href="#tab_password" data-toggle="tab">更改密码</a>
                  </li>
                  <li>
                    <a href="#tab_permission" data-toggle="tab">权限设置</a>
                  </li>
                  <li>
                    <a href="#tab_menu" data-toggle="tab">菜单配置</a>
                  </li>
                </ul>
              </div>
              <div class="portlet-body">
                <div class="tab-content">
                  <!-- PERSONAL INFO TAB -->
                  <div class="tab-pane active" id="tab_profile">
                    <form id="updateForm" role="form" action="~/User/UpdateUser?ajax=true">
                      <input type="hidden" name="uid" value="@UserInfo.UID" />
                      <div class="form-body">
                        <div class="form-group">
                          <label class="control-label">姓氏</label>
                          <span></span>
                          <input name="firstname" type="text" placeholder="姓氏" class="form-control" value="@UserInfo.FirstName" />
                        </div>
                        <div class="form-group">
                          <label class="control-label">名字</label>
                          <span></span>
                          <input name="lastname" type="text" placeholder="名字" class="form-control" value="@UserInfo.LastName" />
                        </div>
                        <div class="form-group">
                          <label class="control-label">中文名？</label>
                          <div class="checkbox-list">
                            <label class="checkbox-inline">
                              <input type="radio" name="cnname" value="true" @(UserInfo.CNName ? "checked=\"checked=\"" : "")/> 是
                            </label>
                            <label class="checkbox-inline">
                              <input type="radio" name="cnname" value="false" @(!UserInfo.CNName ? "checked=\"checked=\"" : "")/> 否
                            </label>
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="control-label">分组</label>
                          <div class="checkbox-list">
                            @foreach(TBM.Models.Group item in ViewBag.Groups){
                            <label class="checkbox-inline">
                              <input type="checkbox" name="groups" id="@("chkGroup_" + item.GID)" value="@item.GID" @(item.IsChecked ? "checked=\"checked\"" : "")/> @item.GroupName
                            </label>
                            }
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="control-label">Email</label>
                          <span></span>
                          <input name="email" type="text" placeholder="Email" class="form-control" value="@UserInfo.Email" />
                        </div>
                        <div class="form-group">
                          <label class="control-label">通讯电话</label>
                          <span></span>
                          <input name="phone" type="text" placeholder="通讯电话" class="form-control" value="@UserInfo.Phone" />
                        </div>
                        <div class="form-group">
                          <label class="control-label">QQ</label>
                          <span></span>
                          <input name="qq" type="text" placeholder="QQ" class="form-control" value="@UserInfo.QQ" />
                        </div>
                        <div class="form-group">
                          <label class="control-label">备注信息</label>
                          <textarea name="memo" class="form-control" rows="3" placeholder="关于TA的备注">@UserInfo.Memo</textarea>
                        </div>
                        <div class="margiv-top-10">
                          <button id="btnUpdateUser" type="button" class="btn green-haze">更新</button>
                          <button id="btnUpdateUserCancel" type="button" class="btn default">取消</button>
                        </div>
                      </div>
                    </form>
                  </div>
                  <!-- END PERSONAL INFO TAB -->
                  <!-- CHANGE AVATAR TAB -->
                  <div class="tab-pane" id="tab_avatar">
                    <div class="alert alert-warning">
                      更新头像后，原始头像将被删除
                    </div>
                    <form id="avatarForm" action="~/User/UpdateAvatar?ajax=true" role="form">
                      <div class="form-group clearfix">
                        <div id="avatarLargePreview" class="large-preview pull-left">
                          <img src="@LargePic" height="125" />
                        </div>
                        <div  id="avatarSmallPreview" class="small-preview pull-left ml-20">
                          <img src="@SmallPic" height="30" />
                        </div>
                        <span class="btn btn-primary fileinput-button pull-left ml-20">
                            <i class="fa fa-photo"></i>
                            <span>选择头像</span>
                            <input id="fileAvatar" type="file" name="avatar" />
                        </span>
                        <input type="hidden" name="uid" value="@UserInfo.UID" />
                      </div>
                      <div class="margin-top-10">
                        <button id="btnUpload" type="button" class="btn green-haze">更新头像</button>
                        <button id="btnCancelUpload" type="button" class="btn default">取消</button>
                      </div>
                    </form>
                  </div>
                  <!-- END CHANGE AVATAR TAB -->
                  <!-- CHANGE PASSWORD TAB -->
                  <div class="tab-pane" id="tab_password">
                    <form id="updatePasswordForm" action="~/User/UpdatePWD?ajax=true">
                      <div class="hide">
                        <!--用来修正webkit浏览器自动补全密码问题-->
                        <input name="no" type="password" class="form-control" />
                        <input type="hidden" name="uid" value="@UserInfo.UID" />
                      </div>
                      <div class="form-group">
                        <label class="control-label">当前密码</label>
                        <span></span>
                        <input name="currpassword" type="password" class="form-control" />
                      </div>
                      <div class="form-group">
                        <label class="control-label">新的密码</label>
                        <span></span>
                        <input id="newpassword" name="newpassword" type="password" class="form-control" />
                      </div>
                      <div class="form-group">
                        <label class="control-label">确认密码</label>
                        <span></span>
                        <input name="confirmpassword" type="password" class="form-control" />
                      </div>
                      <div class="margin-top-10">
                        <button id="btnUpdatePWD" type="button" class="btn green-haze">更新密码</button>
                        <button id="btnCancelUpdatePWD" type="button" class="btn default">取消</button>
                      </div>
                    </form>
                  </div>
                  <!-- END CHANGE PASSWORD TAB -->
                  <!-- PRIVACY SETTINGS TAB -->
                  <div class="tab-pane" id="tab_permission">
                    <form id="updatePermissionForm" action="~/User/UpdateUserPermission?ajax=true">
                      <input type="hidden" name="uid" value="@UserInfo.UID" />
                      <table class="table table-light">
                        <tbody>
                          @foreach(var Parent in ViewBag.ModuleList){
                          <tr>
                            <td>
                              <div class="checkbox-list mb-10">
                                <label class="checkbox-inline align-left">
                                  <input name="moduleid" type="checkbox" value="@Parent.Key.ID" 
                                    @(Parent.Key.IsChecked ? "checked=\"checked\"" : "")
                                    @(ViewBag.IsCurrentUser ? "disabled=\"disabled\"" : "")/>
                                    <b> @("[" + Parent.Key.ControllerDescr + "] " + Parent.Key.ActionDescr) </b>
                                </label>
                              </div>
                              <div class="checkbox-list pl-50">
                                @foreach(TBM.Models.Module item in Parent.Value){
                                <label class="checkbox-inline align-left">
                                  <input name="moduleid" type="checkbox" value="@item.ID" 
                                    @(item.IsChecked ? "checked=\"checked\"" : "")
                                    @(ViewBag.IsCurrentUser ? "disabled=\"disabled\"" : "")/> @item.ActionDescr
                                </label>
                                }
                              </div>
                            </td>
                          </tr>
                          }
                        </tbody>
                      </table>
                      <!--end profile-settings-->
                      @if(!ViewBag.IsCurrentUser){
                      <div class="margin-top-10">
                        <button id="btnUpdatePermission" type="button" class="btn green-haze">更新</button>
                        <button id="btnCancelUpdatePermission" type="button" class="btn default">取消</button>
                      </div>
                      }
                    </form>
                  </div>
                  <!-- END PRIVACY SETTINGS TAB -->
                  <!-- BEGIN MENU SETTING TAB -->
                    <div class="tab-pane" id="tab_menu">
					    <form id="updateMenuSettingForm" action="~/User/UpdateUserMenuPermission">
						    <input type="hidden" name="uid" value="@UserInfo.UID" />
						    <table class="table table-light">
							    <tbody>
								    @foreach(TBM.Models.MainMenu menuItem in MenuList){
								    <tr>
									    <td>
										    <div class="checkbox-list mb-10">
											    <label class="checkbox-inline align-left">
												    @if(menuItem.IsChecked){
													    <input type="checkbox" name="id" value="@menuItem.ID" checked="checked" @(ViewBag.IsCurrentUser ? "disabled=\"disabled\"" : "")> 
												    }else{
													    <input type="checkbox" name="id" value="@menuItem.ID"> 
												    }
												    @menuItem.PageName
											    </label>
											    @TreeNodes(menuItem)
										    </div>
									    </td>
								    </tr>
								    }
							    </tbody>
						    </table>
					    </form>
					    @if(!ViewBag.IsCurrentUser){
					    <div class="margin-top-10">
						    <button id="btnUpdateMenuPermission" type="button" class="btn green-haze">更新</button>
						    <button id="btnCancelUpdateMenuPermission" type="button" class="btn default">取消</button>
					    </div>
					    }
				    </div>
                    <!-- END MENU SETTING TAB -->
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- END PROFILE CONTENT -->
    </div>
  </div>
</div>
<script type="text/javascript">
    jQuery(document).ready(function () {
        UserDetail.init();
    });
</script>